package com.yz.code_test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class TestDemo {
    public static void main(String[] args) throws ParseException {


        List<Date> dateRange = getTmeRange("2021-04-22 10:12:33", 300);
        System.out.println(dateRange.toString());


    }

    private static List<Date> getTmeRange(String dateStr, int interval) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ArrayList<Date> dateList = new ArrayList<>();

        Date date = sdf.parse(dateStr);

        Calendar calendar = Calendar.getInstance();

        calendar.setTime(date);
        calendar.add(Calendar.SECOND, -interval);
        Date timeStart = calendar.getTime();
        dateList.add(timeStart);

        calendar.add(Calendar.SECOND, interval * 2);
        dateList.add(calendar.getTime());

        return dateList;
    }
}
